<?php
/**
 * YOS.
 * 7/23/24
 * @Author deepsea
 * @Contact telegram:deepsea159
 */

use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateFastappTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('fastapp_version', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('版本');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->char('version', 32)->nullable()->comment('版本号');
            $table->date('date')->nullable()->comment('更新日期');
            $table->char('url')->nullable()->comment('下载地址');
            $table->char('app_name', 64)->nullable()->comment('应用名称')->default('default');
            $table->json('content')->comment('更新内容');
        });
        Schema::create('fastapp_ad', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('广告表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->char('name')->nullable()->comment('名称');
            $table->integer('start_at')->nullable()->comment('开始时间')->unsigned();
            $table->integer('end_at')->nullable()->comment('结束时间')->unsigned();
            $table->tinyInteger('fixed')->nullable()->comment('永久有效')->unsigned()->default(0);
            $table->json('cover')->nullable()->comment('位置图片');
            $table->json('cover_theme')->nullable()->comment('图片主题');
            $table->tinyInteger('status')->nullable()->comment('1显示')->unsigned()->default(1);
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(0);
            $table->tinyInteger('object_type')->nullable()->comment('数据类型1链接2视频3分享4文章5路径')->unsigned()->default(1);
            $table->bigInteger('object_id')->nullable()->comment('关联数据')->unsigned()->default(0);
            $table->char('url')->nullable()->comment('分享链接');
            $table->json('title')->nullable()->comment('分享标题');
            $table->json('image')->nullable()->comment('分享封面');
            $table->json('desc')->nullable()->comment('分享描述');
            $table->json('content')->nullable()->comment('分享内容');
            $table->char('remark')->nullable()->comment('备注');
            $table->char('code', 32)->nullable()->comment('调用代码');
            $table->unique('code');
        });
        Schema::create('fastapp_ad_position', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('广告位表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->tinyInteger('status')->nullable()->comment('启用0否1是')->default(1);
            $table->char('name')->nullable()->comment('位置名称');
            $table->json('ad_id')->nullable()->comment('投放广告');
            $table->char('code', 32)->nullable()->comment('调用代码');
            $table->unique('code');
        });
        Schema::create('fastapp_article', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('文章表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->json('title')->nullable()->comment('标题');
            $table->json('subtitle')->nullable()->comment('副标题');
            $table->char('author', 128)->nullable()->comment('作者');
            $table->json('cover')->nullable()->comment('封面');
            $table->json('video')->nullable()->comment('视频');
            $table->char('video_duration')->nullable()->comment('视频时长');
            $table->char('release_at')->nullable()->comment('发布日期');
            $table->json('brief')->nullable()->comment('摘要');
            $table->json('content')->nullable()->comment('内容');
            $table->char('remark')->nullable()->comment('备注');
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(100);
            $table->integer('critique')->nullable()->comment('评论数')->unsigned()->default(0);
            $table->integer('views')->nullable()->comment('浏览数')->unsigned()->default(0);
            $table->integer('like')->nullable()->comment('点赞数')->unsigned()->default(0);
            $table->tinyInteger('status')->nullable()->comment('1显示')->unsigned()->default(1);
            $table->char('code', 32)->nullable()->comment('调用代码');
            $table->bigInteger('account_type')->nullable()->unsigned()->default(1);
            $table->unique('code');
            $table->index('account_type');
        });
        Schema::create('fastapp_category', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('分类表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(0);
            $table->bigInteger('parent_id')->nullable()->comment('上级')->unsigned()->default(0);
            $table->tinyInteger('status')->nullable()->comment('1显示')->unsigned()->default(1);
            $table->smallInteger('scene')->nullable()->comment('场景1文章')->unsigned()->default(1);
            $table->integer('num')->nullable()->comment('数量')->unsigned()->default(0);
            $table->bigInteger('view')->nullable()->comment('浏览量')->unsigned()->default(0);
            $table->char('code', 32)->nullable()->comment('调用代码');
            $table->index('code');
        });
        Schema::create('fastapp_category_article', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('分类文章表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('category_id')->nullable()->comment('分类id')->unsigned()->default(0);
            $table->bigInteger('article_id')->nullable()->comment('文章id')->unsigned()->default(0);
            $table->index('category_id');
        });
        Schema::create('fastapp_realname', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('实名表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->integer('code')->nullable()->comment('国家数字代码')->unsigned();
            $table->tinyInteger('type')->nullable()->comment('证件类型1身份证2护照3驾照4其他')->unsigned()->default(1);
            $table->tinyInteger('status')->nullable()->comment('0未核验1通过2拒绝')->unsigned()->default(0);
            $table->char('id_no', 32)->nullable()->comment('号码');
            $table->char('surname')->nullable()->comment('姓氏');
            $table->char('name')->nullable()->comment('姓名');
            $table->tinyInteger('gender')->nullable()->comment('性别1男2女')->unsigned();
            $table->date('birthday')->nullable()->comment('生日');
            $table->char('nation')->nullable()->comment('民族');
            $table->char('address')->nullable()->comment('住址');
            $table->char('issuing_authority')->nullable()->comment('发证机关');
            $table->date('start_at')->nullable()->comment('开始时间');
            $table->date('end_at')->nullable()->comment('结束时间');
            $table->tinyInteger('forever')->nullable()->comment('永久有效1是2否')->unsigned()->default(2);
            $table->char('id_card_front', 64)->nullable()->comment('正面');
            $table->char('id_card_back', 64)->nullable()->comment('反面');
            $table->unique(['id_no', 'code']);
        });
        Schema::create('fastapp_tag', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('标签表');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->tinyInteger('status')->comment('1正常')->unsigned()->default(1);
            $table->integer('sort')->nullable()->comment('排序')->unsigned()->default(0);
            $table->smallInteger('scene')->nullable()->comment('场景101corp201game301ex')->unsigned();
            $table->integer('num')->nullable()->comment('数量')->unsigned()->default(0);
            $table->bigInteger('view')->nullable()->comment('浏览量')->unsigned()->default(0);
        });
        Schema::create('fastapp_tag_article', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('标签文章表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('tag_id')->nullable()->comment('标签id')->unsigned()->default(0);
            $table->bigInteger('article_id')->nullable()->comment('文章id')->unsigned()->default(0);
            $table->index('tag_id');
        });
        Schema::create('fastapp_pay', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('支付平台');
            $table->bigIncrements('id')->comment('主键');
            $table->json('name')->nullable()->comment('名称');
            $table->char('code', 32)->nullable()->comment('标识');
            $table->tinyInteger('status')->comment('1正常')->unsigned()->default(1);
            $table->tinyInteger('is_withdrawal')->comment('提现0否1是')->unsigned()->default(0);
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->char('icon', 64)->comment('icon');
            $table->json('config')->comment('配置');
        });
        Schema::create('fastapp_app_setting', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('应用设置');
            $table->bigIncrements('id')->comment('主键');
            $table->char('name');
            $table->bigInteger('account_type')->unsigned()->default(1);
            $table->char('key', 32);
            $table->char('val', 128);
            $table->unique(['account_type', 'key']);
        });
        Schema::create('fastapp_channel', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('平台渠道');
            $table->bigIncrements('id')->comment('主键');
            $table->char('key');
            $table->bigInteger('admin_id')->unsigned();
            $table->decimal('rate', 4)->default(0);
            $table->unique('admin_id');
            $table->unique('key');
        });
        Schema::create('fastapp_channel_agent', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('代理');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('created_by')->unsigned();
            $table->bigInteger('updated_by')->unsigned();
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('admin_id')->comment('管理员id')->unsigned();
            $table->char('bus_type', 64)->nullable()->comment('业务类型agent_bus_type');
            $table->string('remark')->comment('备注')->nullable();
            $table->unique(['user_id', 'admin_id']);
        });
        Schema::create('fastapp_channel_agent_settlement', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('代理结算');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->tinyInteger('status')->nullable()->comment('发放0否1是')->unsigned()->default(0);
            $table->decimal('amount', 11)->comment('金额')->default(0);
            $table->date('start_at')->nullable();
            $table->date('end_at')->nullable();
            $table->string('remark')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('fastapp_robot', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('机器人');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('shop_id')->unsigned()->default(0);
            $table->tinyInteger('is_admin')->comment('管理员权限0否1是')->unsigned()->default(0);
            $table->integer('account_type')->unsigned()->default(0);
            $table->char('link', 128)->comment('link');
            $table->char('token', 128)->comment('token');
            $table->char('callback', 128)->comment('回调地址');
            $table->string('remark', 128)->comment('备注');
            $table->tinyInteger('type')->comment('1tg')->unsigned()->default(1);
            $table->char('config', 64)->comment('配置')->default('');
            $table->bigInteger('robot_id')->comment('关联机器人')->default(0)->unsigned();
            $table->unique(['token', 'shop_id']);
        });
        Schema::create('fastapp_robot_group', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('机器人群');
            $table->bigIncrements('id')->comment('主键');
            $table->timestamps();
            $table->bigInteger('user_id')->comment('用户id')->unsigned()->default(0);
            $table->tinyInteger('source')->comment('来源1tg')->unsigned()->default(1);
            $table->bigInteger('source_user')->comment('来源用户')->unsigned()->default(0);
            $table->tinyInteger('type')->comment('1普通群2超级群3频道')->unsigned()->default(1);
            $table->bigInteger('shop_id')->unsigned()->default(0);
            $table->char('group_id', 32)->comment('群id');
            $table->char('username', 64)->nullable();
            $table->string('name', 64)->comment('名称');
            $table->string('desc')->comment('描述')->default('');
            $table->bigInteger('num')->comment('人数')->default(0)->unsigned();
            $table->tinyInteger('status')->unsigned()->default(1);
            $table->index('user_id');
            $table->index('group_id');
            $table->index('shop_id');
        });
        Schema::create('fastapp_robot_group_invite', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('机器人群关系');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->tinyInteger('source')->comment('来源1tg')->unsigned()->default(1);
            $table->char('group_id', 32)->comment('群id');
            $table->bigInteger('user_id')->unsigned();
            $table->bigInteger('parent_id')->unsigned();
            $table->index('parent_id');
        });
        Schema::create('fastapp_robot_group_auth', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('机器人群权限');
            $table->bigIncrements('id')->comment('主键');
            $table->tinyInteger('source')->comment('来源1tg')->unsigned()->default(1);
            $table->char('group_id', 32)->comment('群id');
            $table->char('role', 32)->comment('权限');
            $table->bigInteger('bot_id')->unsigned();
            $table->index('bot_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('fastapp_version');
        Schema::dropIfExists('fastapp_ad');
        Schema::dropIfExists('fastapp_ad_position');
        Schema::dropIfExists('fastapp_article');
        Schema::dropIfExists('fastapp_category');
        Schema::dropIfExists('fastapp_category_article');
        Schema::dropIfExists('fastapp_realname');
        Schema::dropIfExists('fastapp_tag');
        Schema::dropIfExists('fastapp_tag_article');
        Schema::dropIfExists('fastapp_pay');
        Schema::dropIfExists('fastapp_app_setting');
        Schema::dropIfExists('fastapp_channel');
        Schema::dropIfExists('fastapp_channel_agent');
        Schema::dropIfExists('fastapp_channel_agent_settlement');
        Schema::dropIfExists('fastapp_robot');
        Schema::dropIfExists('fastapp_robot_group');
        Schema::dropIfExists('fastapp_robot_group_invite');
        Schema::dropIfExists('fastapp_robot_group_auth');
    }
}
